﻿using System;
using System.Reflection;
using System.IO;
using System.Text;

using Vibstudio.X4NET.IO.Path;

namespace Vibstudio.X4NET.Test.Util
{
    internal class IOHelper
    {
        private const string SAMPLE_FILE_DIRECTORY_NAME = "Samples";

        private static readonly string projectPath = AppDomain.CurrentDomain.BaseDirectory;
        private static readonly string projectName = Assembly.GetExecutingAssembly().GetName().Name;
        private static readonly string solutionPath = projectPath.Replace(Path.Combine(projectName, "bin", "Debug"), string.Empty);
        private static readonly string sampleFileRootPath = Path.Combine(solutionPath, SAMPLE_FILE_DIRECTORY_NAME);

        internal static string SampleFileRootPath
        {
            get { return sampleFileRootPath; }
        }

        internal static string ReadText(string path)
        {
            try
            {
                return File.ReadAllText(path, Encoding.GetEncoding("iso-8859-1"));
            }
            catch
            {
                return string.Empty;
            }
        }

        internal static FilePath ComposeSampleFilePath(string fileName)
        {
            return new FilePath(Path.Combine(SampleFileRootPath, fileName));
        }
    }
}
